<!DOCTYPE html>
<!--suppress ALL-->
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>预约单管理</title>
    <link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.7.0/themes/metro-blue/easyui.css">
    <link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.7.0/themes/icon.css">
    <script type="text/javascript" src="/static/jquery-easyui-1.7.0/jquery.min.js"></script>
    <script type="text/javascript" src="/static/jquery-easyui-1.7.0/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/static/jquery-easyui-1.7.0/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">

        var url;

        function searchReservation() {
            $("#dg").datagrid('load', {
                "customer.id": $("#s_customerId").val(),
                "user.id": $("#s_userId").val(),
                "pet.name": $("#s_petName").val(),
                "type": $("#s_type").val(),
                "status": $("#s_status").val()
            });
        }

        function formatCustomer(val, row) {
            if (val == null) {
                return "";
            } else {
                return val.contact;
            }
        }

        function formatPet(val, row) {
            if (val == null) {
                return "";
            } else {
                return val.name;
            }
        }

        function formatUser(val, row) {
            if (val == null) {
                return "";
            } else {
                return val.trueName;
            }
        }

        function formatStatus(val, row) {
            if (val == 0) {
                return "<span style='color: blue'>(°ー°〃)未被预约</span>";
            } else if (val == 1) {
                return "<span style='color: #0c9c6e'>(๑•̀ㅂ•́)و✧预约成功</span>";
            } else if (val == 2) {
                return "<span style='color: red'>ε(┬┬﹏┬┬)3预约失败</span>";
            } else if (val == 3) {
                return "<span style='color:orange;'>┏(＾0＾)┛预约结束</span>";
            }
        }

        function formatDate(val, row) {
            return val.substring(0, 4) + "年" + val.substring(5, 7) + "月" + val.substring(8, 10) + "日 " + val.substring(11, 13) + val.substring(13, 16);
        }

        function deleteReservation() {
            var selectedRows = $("#dg").datagrid("getSelections");
            if (selectedRows.length == 0) {
                $.messager.alert("系统提示", "请选择要删除的数据!");
                return;
            }
            var strIds = [];
            for (var i = 0; i < selectedRows.length; i++) {
                strIds.push(selectedRows[i].id);
            }
            var ids = strIds.join(",");
            $.messager.confirm("系统提示", "您确定要删除这<span style='color: red'>" + selectedRows.length + "</span>条数据吗?", function (r) {
                if (r) {
                    $.post("/admin/reservation/delete", {ids: ids}, function (result) {
                        if (result.success) {
                            $.messager.alert("系统提示", "数据已成功删除!");
                            $("#dg").datagrid("reload");
                        } else {
                            $.messager.alert("系统提示", result.errorInfo);
                        }
                    }, "json");
                }
            });
        }

        function dealReservation(status) {
            var selectedRows = $("#dg").datagrid("getSelections");
            if (selectedRows.length != 1) {
                $.messager.alert("系统提示", "请选择一个要重置的预约！");
                return;
            }
            var id = selectedRows[0].id;
            $.messager.confirm("系统提示", "您确定要重置预约吗?", function (r) {
                if (r) {
                    $.post("/admin/reservation/dealReservation", {
                        status: status,
                        reservationId: id
                    }, function (result) {
                        if (result.success) {
                            $.messager.alert("系统提示", "重置预约成功！");
                            $("#dg").datagrid("reload");
                        } else {
                            $.messager.alert("系统提示", result.errorInfo);
                        }
                    }, "json");
                }
            });
        }
    </script>
</head>
<body style="margin: 1px">
<table id="dg" title="预约单管理" class="easyui-datagrid"
       fitColumns="true" pagination="true" rownumbers="true"
       url="/admin/reservation/list" fit="true" toolbar="#tb">
    <thead>
    <th field="cb" checkbox="true" align="center"></th>
    <th field="type" width="20" align="center">预约类型</th>
    <th field="customer" width="30" align="center" formatter="formatCustomer">所属客户</th>
    <th field="pet" width="30" align="center" formatter="formatPet">客户宠物</th>
    <th field="user" width="20" align="center" formatter="formatUser">接受人</th>
    <th field="createDate" width="50" align="center">创建时间</th>
    <th field="reserveDate" width="50" align="center" formatter="formatDate">可预约时间</th>
    <th field="description" width="50" align="center">预约单描述</th>
    <th field="status" width="40" align="center" formatter="formatStatus">当前状态</th>
    </thead>
</table>

<div id="tb">
    <div>
        <a href="javascript:dealReservation(0)" class="easyui-linkbutton" iconCls="icon-reset" plain="true">重置预约单</a>
        <a href="javascript:deleteReservation()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
        <strong style="font-size: 13px;color: orange">友情提示:如果要删除已处理的预约单,请先将其重置</strong>
    </div>
    <div>
        &nbsp;预约单类型:&nbsp;
        <select class="easyui-combobox" id="s_type" style="width: 110px" editable="false" panelHeight="auto">
            <option value="">所有类型</option>
            <option value="预约医生">预约医生</option>
            <option value="预约美容师">预约美容师</option>
        </select>
        &nbsp;预约单状态:&nbsp;
        <select class="easyui-combobox" id="s_status" style="width: 110px" editable="false" panelHeight="auto">
            <option value="">所有类型</option>
            <option value="0">未被预约</option>
            <option value="1">预约成功</option>
            <option value="3">预约结束</option>
        </select>
        &nbsp;客户名称：<input class="easyui-combobox" id="s_userId" style="width: 100px"
                          data-options="panelHeight:'auto',valueField:'id',textField:'trueName',url:'/admin/user/comboList'"/>
        &nbsp;客户名称：<input class="easyui-combobox" id="s_customerId" style="width: 100px"
                          data-options="panelHeight:'auto',valueField:'id',textField:'contact',url:'/admin/customer/comboList'"/>
        &nbsp;宠物名称:&nbsp;<input type="text" id="s_petName" size="20"
                                onkeydown="if(event.keyCode==13) searchReservation()"/>
        <a href="javascript:searchReservation()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
    </div>
</div>
</body>
</html>